package com.js.auth.server.module.client.service.impl;

import com.js.auth.server.feign.IUserService;
import com.js.auth.server.jwt.user.JwtTokenUtil;
import com.js.auth.server.module.client.service.AuthService;
import com.js.common.exception.auth.UserInvalidException;
import com.js.common.util.RedisKeyUtil;
import com.js.core.constants.CommonConstants;
import com.js.core.util.jwt.IJwtInfo;
import com.js.core.util.jwt.JwtInfo;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ygl
 * @create 2018-11-12
 * @DESCRIPTION
 **/
@Service
public class AuthServiceImpl implements AuthService {

    @Autowired
    private IUserService userService;
    @Autowired
    private JwtTokenUtil jwtTokenUtil;
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public Boolean invalid(String token) throws Exception {
        IJwtInfo infoFromToken = jwtTokenUtil.getInfoFromToken(token);
        redisTemplate.delete(RedisKeyUtil.buildUserAbleKey(infoFromToken.getId(), infoFromToken.getExpireTime()));
        redisTemplate.opsForValue().set(RedisKeyUtil.buildUserDisableKey(infoFromToken.getId(), infoFromToken.getExpireTime()), "1");
        return true;
    }
}
